package com.example.helloword.source;

import android.util.Log;

import com.example.helloword.bean.Book;
import com.example.helloword.bean.Chapter;
import com.example.helloword.utli.JsoupUtli;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public abstract class BaseNovelSource {

    public final static int BOOK_LIST = 0;
    public final static int CHAPTER_LIST = 1;


    public String getIndex() {
        return "https://www.biqupai.com";
    }

    public String getSearchUrl(String searchName) {
        return getIndex() + "/search.php?keyword=" + searchName;
    }

    public List getItems(String html, String cssQuery, int fetchType) {
        Document parse = Jsoup.parse(html);
        Elements select = parse.select(cssQuery);
        List objects = new ArrayList<>();

        Object o = null;
        for (Element e : select) {
            switch (fetchType) {
                case BOOK_LIST: {

                    o = getBooks(e);
                    break;
                }
                case CHAPTER_LIST: {
                    o = getChapters(e);
                    break;
                }

            }

            objects.add(o);


        }

        return objects;

    }
    public String getContent(String html,String cssQuery){
        Document parse = Jsoup.parse(html);
       return parse.select(cssQuery).text();
    }


    public abstract   Book getBooks(Element element);


    public abstract Chapter getChapters(Element element) ;


}
